<template>
  <div>
    <FilterTable
      ref="table"
      columnsRef="ygy_repairProject"
      :columns="columns"
      :dataSource="dataSource"
      :datakey="'rows'"
      height="auto"
      :isSelectColumn="false"
      :onSyncTableData="tableChangeFun"
      :onColumnsChange="columns => (this.columns = columns)"
    ></FilterTable>
  </div>
</template>

<script>
import { dictionary } from '@/utils/dictMixin';
import { getWxlxSelect } from '@/api/repair/repairReception/customer';
import { getBrand, getSeries, getModel, getRegion, getBxgsSelect } from '@/api/customerRepair/customerCare/insuranceDueRemind/index';
import { searchRoleByCode } from '@/api/common/empSelect/index';
import dictCode from '@/utils/dictCode';
import { getNameByIds } from '@/api/repair/common/index.js';
export default {
  name: 'repairProject',
  mixins: [dictionary],
  props: ['rowData', 'roNo', 'allUser', 'chargePartition', 'dataSource'],
  data() {
    return {
      columns: this.createTableColumns(),
      tableData: []
    };
  },
  created() {
    let roNo = this.roNo;
    this.fetchParams = Object.assign({}, { roNo: roNo, ownerCode: this.rowData.ownerCode }, { xhrAbort: false });
  },
  mounted() {
    this.columns.find(x => x.dataIndex === 'chargePartitionCode').dictItems = this.chargePartition;
  },
  methods: {
    // 获取所有的人员
    async getNameByIds(parmas) {
      let res = await getNameByIds(parmas);
      if (res.resultCode == 200) {
        let userList = res.data.map(x => ({ text: x.employeeName, value: x.employeeId + '' }));
        this.columns.find(x => x.dataIndex === 'technician').dictItems = userList;
      }
    },
    dealerTranslate() {
      let userIds = [];
      this.tableData.forEach(item => {
        userIds.push(item.technician);
      });
      if (!userIds.length) return;
      let newUserIds = Array.from(new Set(userIds)); // 数组去重
      let userIdsStr = newUserIds.join(',');
      if (!userIdsStr.length) return;
      this.getNameByIds({ userIds: userIdsStr });
    },
    tableChangeFun(data) {
      this.tableData = data;
      this.dealerTranslate();
    },
    createTableColumns() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 70,
          sorter: true,
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        // {
        //   title: '操作',
        //   dataIndex: 'column-action',
        //   sorter: true,
        //   render: props => {
        //     return (
        //       <el-button size="mini" type="text" onClick={() => this.openWorker(props)}>
        //         派工情况
        //       </el-button>
        //     );
        //   }
        // },
        {
          title: '收费区分',
          dataIndex: 'chargePartitionCode',
          sorter: true,
          dictItems: []
        },
        {
          title: '项目维修类型',
          dataIndex: 'repairTypeCode',
          hidden: true
        },
        {
          title: '项目维修类型',
          dataIndex: 'repairTypeName',
          sorter: true
        },
        // {
        //   title: '故障原因',
        //   dataIndex: 'TROUBLE_CAUSE',
        //   sorter: true,
        //   filter: true,
        //   filterType: 'input',
        //   showOverflowTooltip: true
        // },
        {
          title: '项目代码',
          dataIndex: 'labourCode',
          sorter: true
        },
        {
          title: '维修项目名称',
          dataIndex: 'labourName',
          width: 200,
          sorter: true,
          showOverflowTooltip: true
        },

        {
          title: '工时单价',
          dataIndex: 'labourPrice',
          sorter: true,
          precision: 2
        },
        {
          title: '标准工时',
          dataIndex: 'stdLabourHour',
          sorter: true,
          precision: 2
        },
        {
          title: '工时费',
          dataIndex: 'labourAmount',
          sorter: true,
          precision: 2
        },
        {
          title: '派工工时',
          dataIndex: 'assignLabourHour',
          sorter: true,
          precision: 2
        },
        {
          title: '优惠金额',
          dataIndex: 'discountAmount',
          sorter: true,
          precision: 2
        },
        {
          title: '折扣率',
          dataIndex: 'discount',
          sorter: true,
          precision: 2
        },
        {
          title: '实收金额',
          dataIndex: 'realAmount',
          sorter: true,
          precision: 2
        },
        {
          title: '派工标志',
          dataIndex: 'assignTag',
          sorter: true,
          render: props => {
            return <span>{this.createDictText(props.row.assignTag, '1004')}</span>;
          }
        },
        {
          title: '是否委外',
          dataIndex: 'consignExterior',
          sorter: true,
          dictItems: this.createDictList(1004)
        },
        {
          title: '是否不修',
          dataIndex: 'needlessRepair',
          sorter: true,
          dictItems: this.createDictList(1004)
        },
        {
          title: '不修类型',
          dataIndex: 'needlessType',
          dictItems: this.createDictList(1018)
        },
        {
          title: '不修原因',
          dataIndex: 'needlessReason'
        },
        {
          title: '责任技师',
          dataIndex: 'technician',
          sorter: true,
          dictItems: []
        },
        {
          title: '活动编号',
          dataIndex: 'activityCode',
          sorter: true,
          render: props => {
            return <span>{props.row.activityCode == 'null' ? (props.row.activityCode = '') : props.row.activityCode}</span>;
          }
        },
        {
          title: '检查结果',
          dataIndex: 'remark',
          sorter: true
        }
      ];
    }
  }
};
</script>

<style lang="less"></style>
